package com.qasystem.qa.system.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.qasystem.qa.core.base.BaseController;
import com.qasystem.qa.core.base.BaseEnum;
import com.qasystem.qa.core.base.Result;
import com.qasystem.qa.core.constants.BaseEnums;
import com.qasystem.qa.core.utils.Results;
import com.qasystem.qa.system.entity.Sports;
import com.qasystem.qa.system.service.SportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/public")
@Controller
public class SportsController extends BaseController {
    @Autowired
    private SportsService sportsService;

    @GetMapping("/sportsInfo")
    @ResponseBody
    public Result getSportsInfo() {
        List<Sports> infos = sportsService.selectAll();
        Result result = Results.newResult();
        if (infos != null) {
            result = Results.successWithData(infos, BaseEnums.SUCCESS.code(),BaseEnums.SUCCESS.desc());
        }
        return result;
    }
    @PostMapping("/addInfo")
    @ResponseBody
    public Result addSportsInfo (Sports sports) {
        Result result = null;
        if (sports != null) {
            sportsService.insert(sports);
            result = Results.success(BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
        }
        else {
            result = Results.failure(BaseEnums.FAILURE.code(), BaseEnums.FAILURE.desc());
        }
        return result;

    }

}
